package com.clkj.sunhelp.mvp.publicityshow.publicityofapplyresult;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.clkj.sunhelp.R;
import com.clkj.sunhelp.bean.AreaItem;
import com.clkj.sunhelp.bean.HelpProjKindItem;
import com.clkj.sunhelp.bean.YearItem;
import com.clkj.sunhelp.common.Config;
import com.clkj.sunhelp.common.IntentKey;
import com.clkj.sunhelp.common.RequestAndResultCode;
import com.clkj.sunhelp.mvp.areachoose.DialogFragmentAreaChoose;
import com.clkj.sunhelp.mvp.base.BaseActivity;
import com.clkj.sunhelp.mvp.examstatuschoose.DialogFragmentExamStatusChoose;
import com.clkj.sunhelp.mvp.projkindchoose.ActivityChooseProKind;
import com.clkj.sunhelp.mvp.releaseyear.DialogFragmentToChooseReleaseYear;
import com.clkj.sunhelp.util.ToastUtil;

/**
 * 申请结果公示主界面
 * Created by Administrator on 2017/3/27.
 */

public class ActivityPublicityOfApplyResultSearchView extends BaseActivity implements View.OnClickListener, DialogFragmentAreaChoose.AreaChooseListener, DialogFragmentToChooseReleaseYear.ReleaseYearChooseListener,DialogFragmentExamStatusChoose.ExamStatusChooseListener {

    private TextView tvChooseProj;
    private TextView tvChooseChooseQuxian;
    private TextView tvChooseXiangzhen;
    private TextView tvChooseShequcun;


    private EditText etInputIdcardno;
    private TextView tvChooseExamStatus;
    private TextView tvChooseReleaseYear;
    private TextView tvSubmit;

    //选择的审核状态
    String mChoosedExamStatus;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_publicity_apply_result_search_view);
        initTitleWithRightTvOrIv(null, null, "审定结果公示", true, null, null);
        initData();
        assignView();
        initView();
    }

    @Override
    public void initData() {

    }

    @Override
    public void assignView() {
        tvChooseProj = (TextView) findViewById(R.id.tv_choose_proj);
        tvChooseChooseQuxian = (TextView) findViewById(R.id.tv_choose_choose_quxian);
        tvChooseXiangzhen = (TextView) findViewById(R.id.tv_choose_xiangzhen);
        tvChooseShequcun = (TextView) findViewById(R.id.tv_choose_shequcun);

        etInputIdcardno = (EditText) findViewById(R.id.et_input_idcardno);
        tvChooseExamStatus = (TextView) findViewById(R.id.tv_choose_exam_status);
        tvChooseReleaseYear = (TextView) findViewById(R.id.tv_choose_release_year);
        tvSubmit = (TextView) findViewById(R.id.tv_submit);
    }

    @Override
    public void initView() {
        tvSubmit.setOnClickListener(this);

        tvChooseChooseQuxian.setOnClickListener(this);
        tvChooseXiangzhen.setOnClickListener(this);
        tvChooseShequcun.setOnClickListener(this);

        tvChooseProj.setOnClickListener(this);
        tvChooseReleaseYear.setOnClickListener(this);

        tvChooseExamStatus.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_choose_exam_status:

                DialogFragmentExamStatusChoose dialogFragmentExamStatusChoose
                        = DialogFragmentExamStatusChoose.getInstance(null,"选择审核状态");
                dialogFragmentExamStatusChoose.setExamStatusChooseListener(this);
                dialogFragmentExamStatusChoose.show(getSupportFragmentManager(), Config.DIALOG_FRAGMENT_TAG_TO_CHOOSE_EXAM_STATUS);

                break;
            case R.id.tv_choose_release_year:

                DialogFragmentToChooseReleaseYear dialogFragmentToChooseReleaseYear
                        = DialogFragmentToChooseReleaseYear.getInstance(null);
                dialogFragmentToChooseReleaseYear.setReleaseYearChooseListener(this);
                dialogFragmentToChooseReleaseYear.show(getSupportFragmentManager(), Config.DIALOG_FRAGMENT_TAG_TO_CHOOSE_RELEASE_YEAR);


                break;

            case R.id.tv_choose_proj:

                Intent toChooseProKind = new Intent(this, ActivityChooseProKind.class);
                startActivityForResult(toChooseProKind, RequestAndResultCode.REQUEST_CODE_TO_CHOOSE_PROJ_KIND);

                break;
            case R.id.tv_submit:
                Intent toShowPublicityOfApplyResultView = new Intent(this,ActivityPublicityOfApplyResultShowView.class);

                toShowPublicityOfApplyResultView.putExtra(IntentKey.INTENT_KEY_PROJ_KIND,null != mChoosedProjKind?mChoosedProjKind.getItemName():"");
                toShowPublicityOfApplyResultView.putExtra(IntentKey.INTENT_KEY_QUXIAN,null != mChoosedQuXian ?mChoosedQuXian.getAreaName():"");
                toShowPublicityOfApplyResultView.putExtra(IntentKey.INTENT_KEY_XIANGZHEN_JIEDAO,null != mChoosedXiangZhen ? mChoosedXiangZhen.getAreaName():"");
                toShowPublicityOfApplyResultView.putExtra(IntentKey.INTENT_KEY_CUNLUO_SHEQU,null != mChoosedCunLuo ? mChoosedCunLuo.getAreaName():"");
                toShowPublicityOfApplyResultView.putExtra(IntentKey.INTENT_KEY_IDCARD_NO,etInputIdcardno.getText().toString());
                toShowPublicityOfApplyResultView.putExtra(IntentKey.INTENT_KEY_EXAM_STATUS, TextUtils.isEmpty( mChoosedExamStatus ) == false ? mChoosedExamStatus : "");
                toShowPublicityOfApplyResultView.putExtra(IntentKey.INTENT_KEY_RELEASE_YEAR,null != mChoosedReleaseYearItem ? mChoosedReleaseYearItem.getYearValue():"");

                startActivity(toShowPublicityOfApplyResultView);

                /*mProjKind = getIntent().getStringExtra(IntentKey.INTENT_KEY_PROJ_KIND);
                mQuXian = getIntent().getStringExtra(IntentKey.INTENT_KEY_QUXIAN);
                mJieDaoOrXiangZhen = getIntent().getStringExtra(IntentKey.INTENT_KEY_XIANGZHEN_JIEDAO);
                mCunLuoOrSheQu = getIntent().getStringExtra(IntentKey.INTENT_KEY_CUNLUO_SHEQU);
                mIdCardNo = getIntent().getStringExtra(IntentKey.INTENT_KEY_IDCARD_NO);
                //审核状态
                mExamStatus = getIntent().getStringExtra(IntentKey.INTENT_KEY_EXAM_STATUS);
                //发放年度
                mReleaseYear = getIntent().getStringExtra(IntentKey.INTENT_KEY_RELEASE_YEAR);
                */

                break;
            case R.id.tv_choose_choose_quxian:
                DialogFragmentAreaChoose dialogAreaChooseQuXian
                        = DialogFragmentAreaChoose.getInstance(null, "请选择区县", Config.TYPE_AREA_QUXIAN);
                dialogAreaChooseQuXian.setAreaChooseListener(this);
                dialogAreaChooseQuXian.show(getSupportFragmentManager(), Config.DIALOG_FRAGMENT_TAG_AREA_CHOOSE);


                break;
            case R.id.tv_choose_xiangzhen:
                if (null != mChoosedQuXian) {
                    DialogFragmentAreaChoose dialogAreaChooseXiangZhen
                            = DialogFragmentAreaChoose.getInstance(mChoosedQuXian.getId(), "请选择乡镇", Config.TYPE_AREA_XIANGZHEN);

                    dialogAreaChooseXiangZhen.setAreaChooseListener(this);
                    dialogAreaChooseXiangZhen.show(getSupportFragmentManager(), Config.DIALOG_FRAGMENT_TAG_AREA_CHOOSE);

                } else {
                    ToastUtil.showShort(this, "请先选择区县");
                }


                break;
            case R.id.tv_choose_shequcun:

                if (null != mChoosedXiangZhen) {
                    DialogFragmentAreaChoose dialogAreaChooseSheQuCun
                            = DialogFragmentAreaChoose.getInstance(mChoosedXiangZhen.getId(), "请选择社区（村）", Config.TYPE_AREA_CUNLUO);
                    dialogAreaChooseSheQuCun.setAreaChooseListener(this);
                    dialogAreaChooseSheQuCun.show(getSupportFragmentManager(), Config.DIALOG_FRAGMENT_TAG_AREA_CHOOSE);

                } else {
                    ToastUtil.showShort(this, "请先选择乡镇（街道））");
                }


                break;

        }
    }


    AreaItem mChoosedQuXian;
    AreaItem mChoosedXiangZhen;
    AreaItem mChoosedCunLuo;

    @Override
    public void onAreaChoose(AreaItem areaItem, int type) {
        switch (type) {
            case Config.TYPE_AREA_QUXIAN:

                mChoosedQuXian = areaItem;

                tvChooseChooseQuxian.setText(mChoosedQuXian.getAreaName());

                break;
            case Config.TYPE_AREA_XIANGZHEN:

                mChoosedXiangZhen = areaItem;

                tvChooseXiangzhen.setText(mChoosedXiangZhen.getAreaName());
                break;
            case Config.TYPE_AREA_CUNLUO:

                mChoosedCunLuo = areaItem;
                tvChooseShequcun.setText(mChoosedCunLuo.getAreaName());

                break;
        }
    }

    YearItem mChoosedReleaseYearItem;

    @Override
    public void onReleaseYearChoose(YearItem chooseYearItem) {
        mChoosedReleaseYearItem = chooseYearItem;
        tvChooseReleaseYear.setText(mChoosedReleaseYearItem.getYearName());
    }

    HelpProjKindItem mChoosedProjKind;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case RequestAndResultCode.REQUEST_CODE_TO_CHOOSE_PROJ_KIND:
                if (resultCode == RequestAndResultCode.RESULT_CODE_TO_CHOOSE_PROJ_KIND_SUCCESS) {
                    mChoosedProjKind = (HelpProjKindItem) data.getSerializableExtra(IntentKey.INTENT_KEY_PROJ_KIND);
                    tvChooseProj.setText(mChoosedProjKind.getItemName());
                }
                break;
        }
    }


    @Override
    public void onExamStatusChoose(String choosedExamStatus) {
        mChoosedExamStatus = choosedExamStatus;
        tvChooseExamStatus.setText(mChoosedExamStatus);
    }
}
